package main.gui.dataobjecteditor;

import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import configuration.Paths;

public class AttributeNamePanel extends JPanel {

	private static final long serialVersionUID = -2892121194732279135L;

	public AttributeNamePanel(String attrDisplayName, String helpText) {
		this.setLayout(new FlowLayout(FlowLayout.LEFT));

		// Add help icon link
		JButton helpButton = new JButton(new ImageIcon(Paths.imagesPath
				+ File.separator
				+ "help_icon.png"));
		helpButton.addActionListener(new HelpButtonListener(helpText, this));
		this.add(helpButton);

		// Add attribute name label
		JLabel attrNameLabel = new JLabel(attrDisplayName);
		attrNameLabel.setFont(DataObjectEditor.ATTRIBUTE_FONT);
		this.add(attrNameLabel);
	}

	protected class HelpButtonListener implements ActionListener {

		private String helpText;
		private JComponent parent;

		public HelpButtonListener(String helpText, JComponent parent) {
			this.helpText = helpText;
		}

		@Override
		public void actionPerformed(ActionEvent arg0) {
			JOptionPane.showMessageDialog(parent, helpText, "Help",
					JOptionPane.INFORMATION_MESSAGE);
		}
	}

}
